//
//  UTSubscriptionModel.swift
//  UniversalTool
//
//  Created by LGB on 2025/3/6.
//

import UIKit
import SwiftyJSON
import ObjectMapper

class UTTranslatorModel: NSObject, Mappable {

    var en: String?
    var cn: String?

    required init?(map: Map) {}

    func mapping(map: Map) {
        en <- map["en"]
        cn <- map["cn"]
    }
    
    static func loadLocalJSON(filename: String) -> [UTTranslatorModel]? {
        if let path = Bundle.main.path(forResource: filename, ofType: "json") {
            do {
                let data = try Data(contentsOf: URL(fileURLWithPath: path))
                let json = try JSON(data: data)
                var proverbs: [UTTranslatorModel] = []
                if let items = json.array {
                    for item in items {
                        if let proverb = UTTranslatorModel(JSON: item.dictionaryObject ?? [:]) {
                            proverbs.append(proverb)
                        }
                    }
                }
                return proverbs
            } catch {
                print("Error loading or parsing JSON: \(error)")
                return nil
            }
        }
        return nil
    }
    
}
